package com.ruoyi.web.controller.erp.planner;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.erp.planner.domain.Planner;
import com.ruoyi.erp.planner.service.PlannerService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author QiuRongYu@itcast.cn
 * @version 1.0
 * @date 2020/12/28
 */
@RestController
@RequestMapping("planner")
public class PlannerController extends BaseController {
    @Resource
    private PlannerService plannerService;
//    private String prefix = "erp/planner";

    /**
     * 根据id删除
     * @param ids
     * @return
     */
    @PreAuthorize("@ss.hasPermi('planner:planner:remove')")
    @PostMapping("/remove/{ids}")
    @ResponseBody
    public AjaxResult remove(@PathVariable("ids") String ids){
        plannerService.remove(ids);
        return AjaxResult.success("删除成功");
    }

    /**
     * 修改计划人
     * @param planner
     * @return
     */
    @PreAuthorize("@ss.hasPermi('planner:planner:edit')")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult plannerEdit(@RequestBody Planner planner){
        plannerService.plannerEdit(planner);
        return AjaxResult.success("修改成功");
    }
    /**
     * 根据id查询详情
     * @param buyerCode
     * @return
     */
  @GetMapping("/plannerId/{id}")
  public AjaxResult plannerIds(@PathVariable("id")String buyerCode ){
      AjaxResult ajax = AjaxResult.success();
      if (StringUtils.isNotNull(buyerCode))
      {
          ajax.put(AjaxResult.DATA_TAG, plannerService.plannerIds(buyerCode));
      }
      return ajax;
  }

    /**
     * 新增计划人
     * @param planner
     * @return
     */
    @PreAuthorize("@ss.hasPermi('planner:planner:add')")
    @PostMapping("/addList")
    @ResponseBody
    public AjaxResult plannerAdd(@RequestBody Planner planner){
        plannerService.plannerAdd(planner);
        return AjaxResult.success("添加成功");
    }
    /**
     * 查询列表
     * @param planner
     * @return
     */
    @PostMapping("/plannerList")
    @ResponseBody
    public TableDataInfo plannerList(Planner planner){
       List<Planner>list= plannerService.plannerList(planner);
       return getDataTable(list);
    }
}
